package nevo.pkgs.es;

import java.util.*;

import nevo.core.*;

public abstract class Breeder
{
	public Map<String,Object> breed(IRecord i1, IRecord i2) throws Exception
	{		
      Map<String,Object> child = (Map<String,Object>) this.clone();
		Map<String, Object> mvals = i1.getInput();
		
		String key;
		Object val1, val2, childval;
		for (Map.Entry<String, Object> entry: i2.getInput().entrySet()) {
			key = entry.getKey();
			if (!mvals.containsKey(key)) {
				throw new Exception("Cannot breed pair, missing parameter: " + key + "");
			}
			val1 = entry.getValue();
			val2 = mvals.get(key);
			childval = breed(val1, val2);
			child.put(key, childval);
		}
		
		return child;
	}
	
	protected abstract Object breed(Object val1, Object val2) throws Exception;
}
